package com.aurora.oa.work.view;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.aurora.oa.Constants.AuroraConstants;
import com.aurora.oa.R;
import com.aurora.oa.activity.BaseActivity;
import com.aurora.oa.application.MyApplication;
import com.aurora.oa.listener.OnRequestDailyDataListener;
import com.aurora.oa.login.model.UserInfo;
import com.aurora.oa.model.RequestHttpModel;
import com.aurora.oa.model.RequestHttpModelImpl;
import com.aurora.oa.work.bean.DailyDataBean;
import com.facebook.drawee.view.SimpleDraweeView;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/4/25 0025.
 */
public class DailyMainActivity extends BaseActivity {
    @Bind(R.id.sdv_head_img)
    SimpleDraweeView sdvHeadImg;
    @Bind(R.id.tv_title)
    TextView tvName;
    @Bind(R.id.tv_postname)
    TextView tvPostname;
    @Bind(R.id.ll_content)
    LinearLayout llContent;
    RequestHttpModel model= new RequestHttpModelImpl();
    String[] contentTitle = new String[]{
            "当月签到",
            "工作日总结",
            "工作周总结",
            "工作月总结",
            "年终总结",
    };
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initTitlebar(true, "日常", true);
        setMyContentView(R.layout.activity_daily);
        ButterKnife.bind(this);
        initView();
        getData();
    }

    private void initView() {
        UserInfo userinfo =MyApplication.getInstance().getLoginUser();
        sdvHeadImg.setImageURI(AuroraConstants.BASE_SERVER_URL+"/"+userinfo.getHeadimg());
        tvName.setText(userinfo.getName());
        tvPostname.setText(userinfo.getPostname());
    }

    private void getData() {
        model.getDailyData(new OnRequestDailyDataListener() {
            @Override
            public void onRequestDailyDataSuccess(DailyDataBean dailyDataBean) {
                addContent(dailyDataBean);
            }

            @Override
            public void onRequestDailyDataFail(String message) {

            }
        });
    }

    private void addContent(DailyDataBean dailyDataBean) {
        int[] number =new int[5];
        number[0]=dailyDataBean.signNumber;
        number[1]=dailyDataBean.dailyWorkLogNumber;
        number[2]=dailyDataBean.weekWorkLogNumber;
        number[3]=dailyDataBean.monthWorkLogNumber;
        number[4]=dailyDataBean.yearWorkLogNumber;
        for(int i =0;i<contentTitle.length;i++){
            View view = View.inflate(this,R.layout.item_key_value,null);
            TextView tv_key = (TextView) view.findViewById(R.id.tv_key);
            TextView tv_value = (TextView) view.findViewById(R.id.tv_remark);
            tv_key.setText(contentTitle[i]);
            tv_value.setText(number[i]+"");
            llContent.addView(view);
        }
    }


}
